const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const FileListPlugin = require('./plugins/file-list-plugin')

module.exports = {
  entry: {
    index: './src/index.js',
    other: './src/other.js',
  },
  output: {
    filename: '[name]-[contenthash:8].js',
    path: path.resolve(__dirname, 'dist'),
    clean: true,
  },
  // watch: true,
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
    extensions: ['.js', '.json', '.jsx'],
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-env'],
            },
          },
        ],
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader'],
      },
      {
        test: /\.md$/,
        use: ['html-loader', './loader/markdown-loader'],
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html',
      filename: 'index.html',
      chunks: ['index'],
      title: 'index',
    }),
    new HtmlWebpackPlugin({
      template: './public/other.html',
      filename: 'other.html',
      chunks: ['other'],
      title: 'other',
    }),
    new MiniCssExtractPlugin(),
    new FileListPlugin(),
  ],
}
